package com.four.peoplemanage.gift.dao;

import com.four.peoplemanage.gift.entity.Gift;
import com.four.peoplemanage.overtime.entity.Overtime;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GiftDao {
    //添加礼品
    @Insert("insert into gift (information_id,giftname,giftnumber,gift_claim_status,status)"+
            "values (#{information_id},#{giftname},#{giftnumber},#{gift_claim_status},#{status})")
    public int addGift(Gift gift);


    //分页查询
    @Select("<script>" +
            "SELECT * FROM gift" +
            "  <where>" +
            "    <if test=\" giftname != null\">" +
            "       giftname = #{giftname} " +
            "    </if>" +
            "    <if test=\" gift_claim_status != null\">" +
            "       and gift_claim_status = #{gift_claim_status} " +
            "    </if>" +
            " and status='1' "+
            "  </where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Gift> getGift(int start, int size, String giftname, String gift_claim_status);

    @Select("<script>" +
            "select count(*) from gift" +
            "  <where>" +
            "    <if test=\" giftname != null\">" +
            "       giftname = #{giftname} " +
            "    </if>" +
            "    <if test=\" gift_claim_status != null\">" +
            "       and gift_claim_status = #{gift_claim_status} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countGift(String giftname, String gift_claim_status);


    //分页查询
    @Select("<script>" +
            "SELECT * FROM gift" +
            "  <where>" +
            "    <if test=\" giftname != null\">" +
            "       giftname = #{giftname} " +
            "    </if>" +
            "    <if test=\" gift_claim_status != null\">" +
            "       and gift_claim_status = #{gift_claim_status} " +
            "    </if>" +
            "  </where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Gift> getGift1(int start, int size, String giftname, String gift_claim_status);

    @Select("<script>" +
            "select count(*) from gift" +
            "  <where>" +
            "    <if test=\" giftname != null\">" +
            "       giftname = #{giftname} " +
            "    </if>" +
            "    <if test=\" gift_claim_status != null\">" +
            "       and gift_claim_status = #{gift_claim_status} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public  int countGift1(String giftname, String gift_claim_status);
    //更新
    @Update("<script>" +
            "update  gift " +
            "        <set>" +
            "            <if test=\"null!= gift_claim_status\">" +
            "                gift_claim_status =#{gift_claim_status}," +
            "            </if>" +
            "            <if test=\"null!= status\">" +
            "                status =#{status}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateOvertimeById(Gift gift);
}
